package com.icinfo.cloud.provider.punish.api.service.impl;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.icinfo.cloud.common.core.config.RedisRepository;
import com.icinfo.cloud.provider.common.constant.Constant;
import com.icinfo.cloud.provider.common.utils.BaseUtil;
import com.icinfo.cloud.provider.common.utils.DateUtil;
import com.icinfo.cloud.provider.common.utils.HeaderUtil;
import com.icinfo.cloud.provider.peripheralinterface.xzzf.service.IXzzfInterfaceService;
import com.icinfo.cloud.provider.punish.api.dto.AbortRestoreCaseDto;
import com.icinfo.cloud.provider.punish.api.dto.CaseAbortRestoreRequest;
import com.icinfo.cloud.provider.punish.api.service.CaseEvidenceShareInventoryApiService;
import com.icinfo.cloud.provider.punish.api.vo.*;
import com.icinfo.cloud.provider.punish.config.service.ISysDepartParamService;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.CaseStatusEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.enums.PartyTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.casemain.mapper.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.model.*;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICaseMainInfoStatusChangeRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.service.ICasePartiesRecordService;
import com.icinfo.cloud.provider.punish.ucase.casemain.vo.CasePartiesRecordVo;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.enums.CaseStatusChangeEffectEnum;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.enums.CaseStatusChangeTypeEnum;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.mapper.CaseDocumentAppraisalYjgzsMapper;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.model.CaseDocumentAppraisalYjgzs;
import com.icinfo.cloud.provider.punish.ucase.investigateevidence.vo.AppraisalReportInfoVo;
import com.icinfo.cloud.xzcf.provider.member.zfpeople.dto.ZfPeopleBaseInfoVO;
import com.icinfo.framework.mybatis.mapper.entity.Example;
import com.icinfo.framework.tools.utils.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.DigestUtils;

import javax.annotation.Resource;
import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;


/**
 * 证据共享库回调
 * @author Administrator
 */
@Service
@Slf4j
public class CaseEvidenceShareInventoryApiServiceImpl implements CaseEvidenceShareInventoryApiService {

    @Resource
    private CaseMainInfoMapper caseMainInfoMapper;

    @Resource
    private CaseMainDetailInfoMapper caseMainDetailInfoMapper;

    @Resource
    private CaseHandlePersonRecordMapper caseHandlePersonRecordMapper;

    @Resource
    private CasePartiesRecordMapper casePartiesRecordMapper;
    @Resource
    private ICasePartiesRecordService casePartiesRecordService;

    @Resource
    private CasePartiesLegalInfoMapper casePartiesLegalInfoMapper;

    @Resource
    private CasePartiesPersonInfoMapper casePartiesPersonInfoMapper;
    @Resource
    private IXzzfInterfaceService xzzfInterfaceService;
    @Resource
    private ICaseMainInfoStatusChangeRecordService caseMainInfoStatusChangeRecordService;
    @Resource
    private CaseMainInfoStatusChangeRecordMapper caseMainInfoStatusChangeRecordMapper;
    @Resource
    private CaseDocumentAppraisalYjgzsMapper caseDocumentAppraisalYjgzsMapper;
    @Resource
    private CaseMainInfoStatusChangeRecordHisMapper caseMainInfoStatusChangeRecordHisMapper;
    @Resource
    private ISysDepartParamService sysDepartParamService;
    @Value("${evidence.url}")
    private String url;
    @Value("${evidence.appKey}")
    private String appKey;
    @Value("${evidence.appSecret}")
    private String appSecret;
    @Value("${evidence.api.appraisalReport}")
    private String appraisalReport;
    @Resource
    private RedisRepository redisRepository;


    /**
     * 证据中心通过本接口获取案件详细信息
     */
    @Override
    public ShareEvidenceCaseVo getCaseInfo(String caseId, String reCollectionName) {
        //判断案件是否存在
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(caseId);
        if(caseMainInfo==null){
            return ShareEvidenceCaseVo.fail("没有案件信息");
        }
        Example casePartiesRecordExample = new Example(CasePartiesRecord.class);
        casePartiesRecordExample.createCriteria().andEqualTo("caseId",caseId).andEqualTo("status",Constant.STRING_1);
        List<CasePartiesRecordVo> partiesRecordList = casePartiesRecordService.getCasePartiesInfo(caseId);
        CasePartiesRecordVo casePartiesRecord = partiesRecordList.get(0);
        // 设置数据
        JSONObject data = new JSONObject();
        // 当事人信息
        AdministrativeCpExtraInfoVo vo = new AdministrativeCpExtraInfoVo();
        CasePartiesPersonInfo partiesPersonInfo = null;
        CasePartiesLegalInfo partiesLegalInfo = null;
        //1.1 判断个人是当事人
        if(PartyTypeEnum.PERSON.getCode().equals(casePartiesRecord.getPartyType())){
            partiesPersonInfo = casePartiesPersonInfoMapper.selectByPrimaryKey(casePartiesRecord.getPartyId());
            PersonInfoVo personInfoVo = new PersonInfoVo();
            personInfoVo.setAddressLive(partiesPersonInfo.getAddress());
            personInfoVo.setAdministrativeCpName(partiesPersonInfo.getName());
            personInfoVo.setAdministrativeCpCertCode(partiesPersonInfo.getCertNo());
            personInfoVo.setAreaCodeLive("");
            personInfoVo.setAreaNameLive("");
            vo.setPersonInfoVo(personInfoVo);
        }else if(PartyTypeEnum.LEGAL.getCode().equals(casePartiesRecord.getPartyType())){
            //1.2 判断公司单位是当事人
            partiesLegalInfo = casePartiesLegalInfoMapper.selectByPrimaryKey(casePartiesRecord.getPartyId());
            GroupInfoVo groupInfoVo = new GroupInfoVo();
            groupInfoVo.setAddressOperating(partiesLegalInfo.getAddress());
            groupInfoVo.setAddressRegisterd(partiesLegalInfo.getAddress());
            groupInfoVo.setAdministrativeCpName(partiesLegalInfo.getEntName());
            groupInfoVo.setAdministrativeCpCertCode(partiesLegalInfo.getUniscid());
            groupInfoVo.setAreaCodeOperating("");
            groupInfoVo.setAreaNameOperating("");
            groupInfoVo.setAreaNameRegisterd("");
            groupInfoVo.setAreaCodeRegisterd("");
            vo.setGroupInfo(groupInfoVo);
        }
        //2.添加返回值
        data.put("administrativeCpExtraInfo",vo);
        // 基本信息
        BaseInfoVo baseInfoVo = new BaseInfoVo();
        //详情信息
        CaseMainDetailInfo caseMainDetailInfo = caseMainDetailInfoMapper.selectByPrimaryKey(caseId);
        //主办人信息
        Example handleMainExample = new Example(CaseHandlePersonRecord.class);
        handleMainExample.createCriteria().andEqualTo("caseId",caseId).andEqualTo("handlePersonType", Constant.STRING_1).andEqualTo("status",Constant.STRING_1);
        CaseHandlePersonRecord caseHandlePersonRecordMain = caseHandlePersonRecordMapper.selectByExample(handleMainExample).get(0);
        baseInfoVo.setAddress(caseMainDetailInfo.getCaseHappenAddressDetail());
        baseInfoVo.setAdminiDivisionCode(caseMainDetailInfo.getCaseHappenAddressAreaCode());
        //当事人
        setParty(casePartiesRecord, partiesPersonInfo, partiesLegalInfo, baseInfoVo);
        baseInfoVo.setCaseDesc(caseMainDetailInfo.getCaseConciseCondition());
        baseInfoVo.setLawDeptName(caseHandlePersonRecordMain.getHandleDeptName());
        baseInfoVo.setLawDeptOrgCode(StringUtils.isNotBlank(caseMainInfo.getCaseOrgCode()) ? caseMainInfo.getCaseOrgCode().substring(13) : caseMainInfo.getCaseOrgCode());
        baseInfoVo.setZfDeptCode(caseHandlePersonRecordMain.getHandleDeptCode());
        baseInfoVo.setZfDeptName(caseHandlePersonRecordMain.getHandleDeptName());
        baseInfoVo.setOrgCode(caseHandlePersonRecordMain.getHandleOrgCode());

        baseInfoVo.setPunishActionName(caseMainDetailInfo.getCaseName());
        baseInfoVo.setPunishCaseCode(caseMainInfo.getCaseNumber());
        baseInfoVo.setBusinessStatus(caseMainInfo.getCaseStatus());
        baseInfoVo.setCaseSummary(caseMainDetailInfo.getCaseReason());

        List<PunishPersonnel> list = new ArrayList();
        // 设置执法人员信息
        setPunishPersonnelList(caseId, baseInfoVo, handleMainExample, caseHandlePersonRecordMain, list);
        baseInfoVo.setReportTime(caseMainDetailInfo.getCaseHappenTime().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        baseInfoVo.setLawDeptDivisionCode(caseMainDetailInfo.getCaseHappenAddressAreaCode());
        baseInfoVo.setLawDeptCode("");
        data.put("baseInfo",baseInfoVo);
        data.put("id",caseId);
        return ShareEvidenceCaseVo.success(data);
    }

    private void setParty(CasePartiesRecordVo casePartiesRecord, CasePartiesPersonInfo partiesPersonInfo, CasePartiesLegalInfo partiesLegalInfo, BaseInfoVo baseInfoVo) {
        baseInfoVo.setAdministrativeCpCertType("111");
        if(PartyTypeEnum.PERSON.getCode().equals(casePartiesRecord.getPartyType())){
            baseInfoVo.setAdministrativeCpName(partiesPersonInfo.getName());
            baseInfoVo.setAdministrativeCpCertCode(partiesPersonInfo.getCertNo());
            baseInfoVo.setAdministrativeCpTel(partiesPersonInfo.getMobile());
            baseInfoVo.setAdministrativeCpType("01");
        }else if(PartyTypeEnum.LEGAL.getCode().equals(casePartiesRecord.getPartyType())){
            baseInfoVo.setAdministrativeCpCertType("001");
            baseInfoVo.setAdministrativeCpType("02");
            baseInfoVo.setAdministrativeCpName(partiesLegalInfo.getEntName());
            baseInfoVo.setAdministrativeCpCertCode(partiesLegalInfo.getUniscid());
            baseInfoVo.setLegalRepresentative(partiesLegalInfo.getLegalName());
            baseInfoVo.setLegalRepresentativeIdcard(partiesLegalInfo.getLegalCertNo());
            baseInfoVo.setLegalRepresentativeType("111");
            baseInfoVo.setAdministrativeCpTel(partiesLegalInfo.getPhone());
        }
    }

    /**
     * 设置执法人员信息
     * @param caseId
     * @param baseInfoVo
     * @param handleMainExample
     * @param caseHandlePersonRecordMain
     * @param list
     */
    private void setPunishPersonnelList(String caseId, BaseInfoVo baseInfoVo, Example handleMainExample, CaseHandlePersonRecord caseHandlePersonRecordMain, List<PunishPersonnel> list) {
        PunishPersonnel punishPersonnelMain = new PunishPersonnel() ;
        punishPersonnelMain.setPunishPersonnelCode("");
        punishPersonnelMain.setPunishPersonnelName(caseHandlePersonRecordMain.getHandlePersonName());
        //协办人信息
        Example handleExample = new Example(CaseHandlePersonRecord.class);
        handleExample.createCriteria().andEqualTo("caseId", caseId).andEqualTo("handlePersonType", Constant.STRING_2).andEqualTo("status",Constant.STRING_1);
        CaseHandlePersonRecord caseHandlePersonRecord= caseHandlePersonRecordMapper.selectByExample(handleExample).get(0);
        PunishPersonnel punishPersonnel = new PunishPersonnel() ;
        punishPersonnel.setPunishPersonnelCode("");
        punishPersonnel.setPunishPersonnelName(caseHandlePersonRecord.getHandlePersonName());
        // 查询执法证号
        JSONObject baseInfoRequest = new JSONObject();
        List<String> userIds = new ArrayList<>();
        userIds.addAll(Arrays.asList(caseHandlePersonRecordMain.getHandlePersonId(),caseHandlePersonRecord.getHandlePersonId()));
        baseInfoRequest.put("userIds", userIds);
        List<ZfPeopleBaseInfoVO> baseInfo = xzzfInterfaceService.getZfPeopleList(baseInfoRequest);
        if (!baseInfo.isEmpty()){
            punishPersonnelMain.setPunishPersonnelCode(baseInfo.get(0).getZfCertList().get(0).getZfCertNo());
            if(baseInfo.size() > 1){
                punishPersonnel.setPunishPersonnelCode(baseInfo.get(1).getZfCertList().get(0).getZfCertNo());
            }
        }
        list.add(punishPersonnel);
        list.add(punishPersonnelMain);
        baseInfoVo.setPunishPersonnelList(list);
    }


    @Override
    public ShareEvidenceStageVo getCaseStage(String id, String reCollectionName) {
        ShareEvidenceStageVo vo = new ShareEvidenceStageVo();
        CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(id);
        if (caseMainInfo != null){
            vo.setCode(200);
            vo.setMessage("success");
            vo.setTotalCount(1);
            vo.setSuccess(true);
            List<JSONObject> data = new ArrayList<>();
//            1	草稿
//            2	未立案
//            3	已立案
//            4	已结案
//            5	已完结

//            立案	cf_la
//            调查取证	cf_dcqzs
//            处罚告知	cf_gz
//            处罚决定	cf_jd
//            处罚执行	cf_zx
//            结案	cf_ja
//            案件延期	cf_yq
//            案件终止	cf_end
//            案件中止	cf_zz
//            案件恢复	cf_hf
//            销案	cf_xa

            JSONObject jsonObject = new JSONObject();
            // 0.待立案，1.立案审批 2.办案中.3.结案
            String zero = "0";
            String one = "1";
            String two = "2";
            String three = "3";
            //环节
            if (zero.equals(caseMainInfo.getCaseStatus())){
                jsonObject.put("alias","0");
            }
            if (one.equals(caseMainInfo.getCaseStatus())){
                jsonObject.put("alias","3");
            }
            if (two.equals(caseMainInfo.getCaseStatus())){
                jsonObject.put("alias","3");
            }
            if (three.equals(caseMainInfo.getCaseStatus())){
                jsonObject.put("alias","4");
            }
            // 阶段
            // 立案
            //调查取证
            //处罚告知
            //处罚决定
            //结案
            String la = "立案";
            String cfdcqzs = "调查取证";
            String cfgz = "处罚告知";
            String cfjd = "处罚决定";
            String cfja = "结案";
            String zx = "执行";
            if (caseMainInfo.getCaseCurrentStageName().contains(la)){
                jsonObject.put("phaseAlias","cf_la");
            }
            if (caseMainInfo.getCaseCurrentStageName().contains(cfdcqzs)){
                jsonObject.put("phaseAlias","cf_dcqzs");
            }
            if (caseMainInfo.getCaseCurrentStageName().contains(cfgz)){
                jsonObject.put("phaseAlias","cf_gz");
            }
            if (caseMainInfo.getCaseCurrentStageName().contains(cfjd)){
                jsonObject.put("phaseAlias","cf_jd");
            }
            if (caseMainInfo.getCaseCurrentStageName().contains(cfja)){
                jsonObject.put("phaseAlias","cf_ja");
            }
            if (caseMainInfo.getCaseCurrentStageName().contains(zx)){
                jsonObject.put("phaseAlias","cf_zx");
            }
            data.add(jsonObject);
            vo.setData(data);
        }
        return vo;
    }

    @Override
    public AbortRestoreCaseVo abortRestoreCase(AbortRestoreCaseDto dto) {
        // 案件无此阶段写死
        AbortRestoreCaseVo vo = new AbortRestoreCaseVo();
        vo.setUrl("");
        vo.setCode(0);
        vo.setSuccess(true);
        vo.setMessage("案件计时操作成功");
        return vo;
    }
    /**
     * 鉴定期间中止或恢复办案计时
     * @author liyafeng
     * @date 2022/4/26
      * @param request
     * @return {@link AbortRestoreCaseVo}
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String,Object> caseAbortRestoreByAppraisal(CaseAbortRestoreRequest request) {
        Map<String,Object> resultMap=new HashMap<>();
        resultMap.put("success","true");
        resultMap.put("message","操作成功");
        resultMap.put("code","200");
        String isRoll=redisRepository.get(request.getCaseId()+"_ABORT_RESTORE_ISROLL");
        //保存暂停/恢复记录
        //1.若为中止计时判断是否存在
        if(Constant.STRING_1.equals(request.getOperateType())) {
            CaseMainInfoStatusChangeRecord caseMainInfoAbortrestoreRecord = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(request.getCaseId(), CaseStatusChangeTypeEnum.SUSPEND.getCode());
            if(null!=caseMainInfoAbortrestoreRecord){
                resultMap.put("success","false");
                resultMap.put("message","操作失败，已存在中止记录！");
                resultMap.put("code","99");
                return resultMap;
            }
            //不存在，插入中止记录
            CaseMainInfoStatusChangeRecord record=new CaseMainInfoStatusChangeRecord();
            record.setId(BaseUtil.createUid());
            record.setCaseId(request.getCaseId());
            record.setCaseNumber(request.getCaseNum());
            record.setChangeSubmitTime(LocalDateTime.now());
            record.setStatus(CaseStatusChangeEffectEnum.VALID.getCode());
            record.setCaseChangeType(CaseStatusChangeTypeEnum.SUSPEND.getCode());
            record.setChangeEffectTime(LocalDateTime.now());
            caseMainInfoStatusChangeRecordMapper.insert(record);
            if(!"true".equals(isRoll)) {
                //更新案件状态为暂停
                CaseMainInfo updateCaseMainInfo = new CaseMainInfo();
                updateCaseMainInfo.setId(request.getCaseId());
                updateCaseMainInfo.setCaseStatus(Constant.STRING_5);
                caseMainInfoMapper.updateByPrimaryKeySelective(updateCaseMainInfo);
            }
        }else if(Constant.STRING_2.equals(request.getOperateType())){
            CaseMainInfoStatusChangeRecord caseMainInfoAbortrestoreRecord = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(request.getCaseId(), CaseStatusChangeTypeEnum.SUSPEND.getCode());
            if(null==caseMainInfoAbortrestoreRecord){
                resultMap.put("success","false");
                resultMap.put("message","操作失败，不存在中止记录，无法恢复！");
                resultMap.put("code","99");
                return resultMap;
            }
            //插入鉴定报告记录
            String timestamp = String.valueOf(System.currentTimeMillis());
            //调用证据库接口获取鉴定报告相关数据
            JSONObject param = new JSONObject();
            param.put("caseId", request.getCaseId());
            param.put("caseNo", "");
            param.put("appKey", appKey);
            param.put("sign", DigestUtils.md5DigestAsHex((appKey + appSecret + timestamp).getBytes(StandardCharsets.UTF_8)));
            param.put("timestamp", timestamp);
            Map<String, String> headers = HeaderUtil.headerInfo();
            String response = HttpUtil.createPost(url+appraisalReport).body(param.toJSONString()).headerMap(headers, true).execute().body();
            JSONObject info = JSONObject.parseObject(response);
            System.out.println(info.toJSONString());
            int code = info.getInteger("code");
            if (200 == code) {
                JSONArray array = info.getJSONArray("data");
                for (int i = 0; i < array.size(); i++) {
                    AppraisalReportInfoVo appraisalReportInfoVo = JSON.parseObject(array.getJSONObject(i).toJSONString(), AppraisalReportInfoVo.class);
                    Example yjgzsExample=new Example(CaseDocumentAppraisalYjgzs.class);
                    yjgzsExample.createCriteria().andEqualTo("reportUid",appraisalReportInfoVo.getReportUid()).andEqualTo("isDeleted","0");
                    List<CaseDocumentAppraisalYjgzs> caseDocumentAppraisalYjgzsList=caseDocumentAppraisalYjgzsMapper.selectByExample(yjgzsExample);
                    if(null!=caseDocumentAppraisalYjgzsList&&caseDocumentAppraisalYjgzsList.size()>0){
                        continue;
                    }
                    CaseDocumentAppraisalYjgzs caseDocumentAppraisalYjgzs=new CaseDocumentAppraisalYjgzs();
                    caseDocumentAppraisalYjgzs.setId(StringUtils.uuid());
                    caseDocumentAppraisalYjgzs.setIsDeleted(Constant.STRING_0);
                    /*UserDTO userDTO= UserUtil.getUserInfo();*/
                    caseDocumentAppraisalYjgzs.setCreateTime(new Date());
                   /* caseDocumentAppraisalYjgzs.setCreateUserId(userDTO.getUserId().toString());
                    caseDocumentAppraisalYjgzs.setCreateUserName(userDTO.getRealName());*/
                    caseDocumentAppraisalYjgzs.setIsGenFile(Constant.STRING_0);
                    caseDocumentAppraisalYjgzs.setAppraisalThings(JSON.toJSONString(appraisalReportInfoVo.getAppraisalThings()));
                    caseDocumentAppraisalYjgzs.setCaseId(request.getCaseId());
                    caseDocumentAppraisalYjgzs.setClientOrgcode(appraisalReportInfoVo.getClientOrgcode());
                    caseDocumentAppraisalYjgzs.setClientOrgname(appraisalReportInfoVo.getClientOrgname());
                    caseDocumentAppraisalYjgzs.setCourierNumber(appraisalReportInfoVo.getCourierNumber());
                    caseDocumentAppraisalYjgzs.setReportUrl(appraisalReportInfoVo.getReportUrl());
                    caseDocumentAppraisalYjgzs.setReportTitle(appraisalReportInfoVo.getReportTitle());
                    caseDocumentAppraisalYjgzs.setReportUid(appraisalReportInfoVo.getReportUid());
                    caseDocumentAppraisalYjgzsMapper.insert(caseDocumentAppraisalYjgzs);
                }
            }else{
                resultMap.put("success","false");
                resultMap.put("message","操作失败，获取鉴定报告失败");
                resultMap.put("code","99");
                return resultMap;
            }
            CaseMainInfoStatusChangeRecord updateRecord=new CaseMainInfoStatusChangeRecord();
            updateRecord.setId(caseMainInfoAbortrestoreRecord.getId());
            updateRecord.setCaseId(request.getCaseId());
            updateRecord.setStatus(Constant.STRING_2);
            updateRecord.setCaseRestoreTime(LocalDateTime.now());
            caseMainInfoStatusChangeRecordMapper.updateByPrimaryKeySelective(updateRecord);
            if(!"true".equals(isRoll)) {
                //恢复则更新案件主表案件期限
                CaseMainInfo caseMainInfo = caseMainInfoMapper.selectByPrimaryKey(request.getCaseId());
                LocalDateTime abortTime = caseMainInfoAbortrestoreRecord.getChangeEffectTime();
                CaseMainInfo updateCaseMainInfo = new CaseMainInfo();
                updateCaseMainInfo.setId(request.getCaseId());
                updateCaseMainInfo.setCaseStatus(CaseStatusEnum.HANDLING_CASE.getCode());
                long days= DateUtil.calculatePastDays(abortTime.toLocalDate());
                updateCaseMainInfo.setCaseTimelimit(caseMainInfo.getCaseTimelimit().plusDays(days));
                caseMainInfoMapper.updateByPrimaryKeySelective(updateCaseMainInfo);
            }
            //清除记录，加入历史
            CaseMainInfoStatusChangeRecord record = caseMainInfoStatusChangeRecordService.getCaseMainInfoStatusChangeRecordByChangeType(request.getCaseId(), CaseStatusChangeTypeEnum.SUSPEND.getCode());
            CaseMainInfoStatusChangeRecordHis recordHis=new CaseMainInfoStatusChangeRecordHis();
            BeanUtils.copyProperties(record,recordHis);
            recordHis.setHisAddTime(LocalDateTime.now());
            caseMainInfoStatusChangeRecordHisMapper.insert(recordHis);
            caseMainInfoStatusChangeRecordMapper.deleteByPrimaryKey(request.getCaseId());

        }else{
            resultMap.put("success","false");
            resultMap.put("message","操作失败，操作类型不正确");
            resultMap.put("code","99");
            return resultMap;
        }
        return resultMap;
    }

}
